package com.whisperarts.financer.app.dialogs;

import org.eclipse.swt.widgets.Shell;

import com.whisperarts.financer.app.utils.DateUtils;
import com.whisperarts.financer.model.account.Account;

public class EditAccountDialog extends AddAccountDialog {
	private final Account account;

	public EditAccountDialog(Shell parentShell, Account account) {
		super(parentShell, account.getAccountType());
		this.account = account;
	}

	@Override
	protected void fillData() {
		textName.setText(account.getName());
		textNote.setText(account.getNote());
		comboCurrency.select(adapter.getCurrencyIndex(account.getCurrency()));
		amountComposite.setAmount(account.getOpeningAmount());		
		labelOpeningDate.setText(DateUtils.dateToString(account.getDateOfCreation()));
	}
	
	@Override
	protected boolean isNameExists(String name) {
		if (!account.getName().equals(name)) {
			return super.isNameExists(name);
		}
		return false;
	}

	@Override
	protected Account getAccountToCreate() {
		return this.account;
	}
}
